-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ecmascript): support dynamic tenary operator jsvalue #6452
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
9 Ignored Deployments
|
✅ This change can build |
🟢 CI successful 🟢Thanks |
Linux Benchmark for e99af59Click to view benchmark
|
|
if test.is_truthy() == Some(true) { | ||
*value = take(cons); | ||
true | ||
} else if test.is_falsy() == Some(true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just test.is_truty() == Some(false)
, right? We can this into a branch above and save some cycles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, this is borrowing existing references from elsewhere (I recall it's binary operation or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this can be a match on is_truty
@@ -1224,6 +1246,12 @@ impl JsValue { | |||
op.joiner(), | |||
b.explain_internal_inner(hints, indent_depth, depth, unknown_depth), | |||
), | |||
JsValue::Tenary(_, test, cons, alt) => format!( | |||
"({}?{}:{})", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit more spacing here would be nice
@@ -1,5 +1,7 @@ | |||
const a = import(true ? "a" : "b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing your tenary support and should evaluate to a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this already works before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tenary passes evaluation at
3c2d29c#diff-2c7634641094d97670b756458b73ab7bc5f6fba2da97471427a6c95795b8562dR429, while dynamic tenary evaluation doesn't seem to pass, so it goes to jsvalue:alternatives.
@@ -3,10 +3,23 @@ | |||
0 -> 2 call = import*0*("a") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already seem to work?
9d1955d
to
408e057
Compare
Linux Benchmark for ce0ac01Click to view benchmark
|
408e057
to
b7a889f
Compare
Linux Benchmark for 4ef8aa7Click to view benchmark
|
b7a889f
to
ec280a4
Compare
Linux Benchmark for 94f2585Click to view benchmark
|
ec280a4
to
c78bd41
Compare
Linux Benchmark for fb3cd66Click to view benchmark
|
Description
context: https://vercel.slack.com/archives/C03EWR7LGEN/p1699990767027949
Currently, if the input source have a non-statically analyzable tenary operator
it becomes to the output like
that takes first value of tenary regardless of the condition. In the analyze phase if tenary is dynamic it retuns
JsValue::Alternatives
, and it takes the first available value immediately.PR changes its behavior by having new type of JsValue for tenary - if condExpr is not statically analyzable. I tried to use existing JsValue but that doesn't seem to work easily out of the box. However I may miss some obvious so PR might be refactored more simple way instead.
Closes PACK-1963